package com.zzj.hotel.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.staticmock.MockStaticEntityMethods;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.zzj.hotel.core.entity.Room;
import com.zzj.hotel.core.entity.RoomResource;
import com.zzj.hotel.core.entity.RoomType;
import com.zzj.hotel.service.RoomService;
import com.zzj.hotel.service.impl.RoomServiceImpl;

@Controller 
@RequestMapping(value={"/room"})
public class RoomController {
	@Autowired RoomService roomservice;
	@RequestMapping(value={"/list"}, method=RequestMethod.GET)
	public ModelAndView showList (Model model){
		List<Room> roomList = roomservice.findAll();
		model.addAttribute("roomList", roomList);
		return new ModelAndView("roomList", "command", new Room());
	}
	@RequestMapping(value={"/add"}, method=RequestMethod.POST)
	public String add(@ModelAttribute("add") Room room ,RoomType roomType, RoomResource roomResource, Model model){
		room.setRoomType(roomType);
		room.setRoomResource(roomResource);
		roomservice.insert(room);
		return "redirect:list";
	}
	@RequestMapping(value={"/delete"}, method=RequestMethod.GET)
	public String delete(HttpServletRequest request){
		String roomId = request.getParameter("roomId");
		roomservice.deleteById(roomId);
		RoomServiceImpl service = (RoomServiceImpl) roomservice;
		return "redirect:list";
	}
	@RequestMapping(value={"/test"}, method=RequestMethod.GET)
	public ModelAndView test(HttpServletRequest request){
		return new ModelAndView("main");
	}
	
}
